﻿<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body">
            <table id="LAY-topic-list" lay-filter="LAY-topic-list"></table>
            <script type="text/html" id="layuiadmin-app-cont-tagsbar">
                <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit"><i class="layui-icon layui-icon-edit"></i>编辑</a>
                <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i class="layui-icon layui-icon-delete"></i>删除</a>
            </script>
        </div>
    </div>
</div>

<script type="text/html" id="IsActive">
    {{#  if(d.IsActive){ }}
    <button class="layui-btn layui-btn-xs">已激活</button>
    {{#  } else { }}
    <button class="layui-btn layui-btn-primary layui-btn-xs">未激活</button>
    {{#  } }}
</script>
<script>

    layui.use(['index','table'], function () {
    var index = layer.load(2, { shade: false });
        var table = layui.table;
        //分类管理
        table.render({
            elem: '#LAY-topic-list'
            , url: '@Html.Raw(Url.Action("Methods", "ExternalAuthentication"))' //模拟接口
            ,method:'post'
            , page: true //开启分页
            , even: true
            , limit: 15
            , limits: [15,30,50,100]
            , cols: [[
                { type: 'numbers', fixed: 'left' }
                , { field: 'Id', width: 100, title: 'ID' }
                , { field: 'FriendlyName', title: '好友名称', minWidth: 100 }
                , { field: 'SystemName', title: '系统名称', minWidth: 100 }
                , { field: 'DisplayOrder', title: '显示顺序', minWidth: 100 }
                , { field: 'IsActive', title: '是否激活', templet: '#IsActive', minWidth: 80, align: 'center' }
                , { title: '操作', width: 150, align: 'center', fixed: 'right', toolbar: '#layuiadmin-app-cont-tagsbar' }
            ]]
            , text: { none: '一条数据也没有^_^' }
            , done: function () {
                layer.close(index);
            }
        });

        //监听工具条
        table.on('tool(LAY-topic-list)', function (obj) {
            var data = obj.data;
            if (obj.event === 'del') {
                layer.confirm('确定删除？', function (index) {
                    obj.del();
                    $.post('@Url.Action("Delete")', { id: obj.data.Id });
                    layer.close(index);
                });

            } else if (obj.event === 'edit') {
                 layer.open({
                    type: 2
                     , title: '编辑'
                     , content: '@Url.Action("MethodUpdate")?id=' + data.Id
                    , shade: 0.2
                    , maxmin: true
                    , shadeClose: true
                    , area: ['900px', '600px']
                    , btn: ['确定', '取消']
                    , yes: function (index, layero) {
                        
                        var submit = layero.find('iframe').contents().find("#set_system_submit_btn");
                        submit.click();
                    }
                });
            }
        });
        var $ = layui.$, active = {
            add: function () {
                layer.open({
                    type: 2
                    , title: '编辑'
                    , content: '@Url.Action("MethodUpdate")'
                    , shade: 0.2
                    , maxmin: true
                    , shadeClose: true
                    , area: ['900px', '600px']
                    , btn: ['确定', '取消']
                    , yes: function (index, layero) {
                        
                        var submit = layero.find('iframe').contents().find("#set_system_submit_btn");
                        submit.click();
                    }
                });
            }
        }
        $('.layui-btn.layuiadmin-btn-tags').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
    });
</script>


